﻿// 2-3 排列还原 (25分).cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
int shunxudui(string a)
{
	int count = 0;
	int i;
	int j;
	for (i = 0; i < a.size(); i++)
	{
		for (j = i; j < a.size(); j++)
		{
			if (i < j && a[i] < a[j])
			{
				count++;
			}
		}

	}
	return count;
}
int main()
{
	int n, k,i,p;
	queue<int>position;
	int ex_count=0;
	string input;
	int re = 0;
	cin >> n >> k;
	//cin >> input;
	int* exit = new int[n+1];
	int* array = new int[n + 1];
	//初始化数组
	for (int i = 0; i < n ; i++)
	{
		exit[i] = 1;
	}
	for (int i = 0; i < n; i++)
	{
		cin >> p;
		array[i] = p;
			if (p!=0)
			{
				exit[p-1] = 0;
				ex_count++;
			}
			else//记录缺失的位置,从零开始
			{
				position.push(i);
			}
	}
	

	//cout<<"缺失的个数"<<n - ex_count<<endl;
	string recover_number="";
	string recover = "";
	for (i = 0; i < n; i++)
	{
		if (exit[i] == 1)
		{
			recover_number = recover_number + to_string(i + 1);
			//cout << i + 1 << endl;//被抹去的数字
		}
	}
	//按第一个一排好的序列，尝试做回插
	//cout << recover_number << endl;
	sort(recover_number.begin(), recover_number.end());
	int j = 0;
	for (i=0; i < n ; i++)
	{
		
		if (array[i] == 0)
		{
			//cout << "recover" << recover << endl;
			recover = recover + recover_number[j]; //r的每一个字符按po的位置回插在原来的字符串中
			
			j++;
		}
		else
		{
			//cout << "recover" << recover <<endl;
			recover = recover + to_string(array[i]);
		}
	}
	//cout << recover << endl;
	if (shunxudui(recover) == k)
	{
		re++;
	};
	while (next_permutation(recover_number.begin(), recover_number.end()))
	{
		recover = "";//开始放入循环后 忘记清零了 
		j = 0;
		for (i = 0; i < n; i++)
		{

			if (array[i] == 0)
			{
				//cout << "recover" << recover << endl;
				recover = recover + recover_number[j]; //r的每一个字符按po的位置回插在原来的字符串中

				j++;
			}
			else
			{
				//cout << "recover" << recover <<endl;
				recover = recover + to_string(array[i]);
			}
		}
		//cout << recover << endl;
		if (shunxudui(recover) == k)
		{
			re++;
		};
	}
	cout << re;
}


